#!/bin/sh
export NLS_LANG=UTF-8
version=V7.0.0
HOST=$1
echo ""
LogFile="upgrade_ksql_gpp.log"
echo "GPP update ${version} begin" >  log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nacos,public" -t -c "\i gppdb/ddl/nacos/nacos_kingbase_ddl.sql"   >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_api_gateway,public" -t -c "\i gppdb/ddl/api-gateway/nupp_api_gateway.sql"   >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_business,public" -t -c "\i gppdb/ddl/business/1.base-all.sql"   >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB  options=-csearch_path=nupp_business,public" -t -c "\i gppdb/ddl/business/3.cnaps-all.sql"   >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_channel,public" -t -c "\i gppdb/ddl/channel/channel(BASE)-all.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_channel,public" -t -c "\i gppdb/ddl/channel/channel(CNAPS)-all.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_checking,public" -t -c "\i gppdb/ddl/checking/1.checking-all.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_checking,public" -t -c "\i gppdb/ddl/checking/3.checking-cnaps-rdb.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_notice,public" -t -c "\i gppdb/ddl/notice/1.notice-all.sql"   >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_position,public" -t -c "\i gppdb/ddl/position/position-all.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_routing,public" -t -c "\i gppdb/ddl/routing/routing-all.sql"   >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_scheduler,public" -t -c "\i gppdb/ddl/scheduler/scheduler-all.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_security,public" -t -c "\i gppdb/ddl/security/security-all.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/ddl/settings/settings-all.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_workflow,public" -t -c "\i gppdb/ddl/workflow/activit-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_workflow,public" -t -c "\i gppdb/ddl/workflow/workflow-all.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_business,public" -t -c "\i gppdb/ddl/business/3.cnaps-view.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_business,public" -t -c "\i gppdb/ddl/business/9.base-view.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_checking,public" -t -c "\i gppdb/ddl/checking/1.checking-view.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_notice,public" -t -c "\i gppdb/ddl/notice/2.notice-view.sql"   >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_position,public" -t -c "\i gppdb/ddl/position/position-view.sql" >>log/$LogFile 2>&1 
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nacos,public" -t -c "\i gppdb/init-data/nacos/nacos-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_business,public" -t -c "\i gppdb/init-data/business/1.t_cnaps_buss_mgt_param-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_business,public" -t -c "\i gppdb/init-data/business/2.t_upp_sys_state-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_business,public" -t -c "\i gppdb/init-data/business/3.message_scope_cnaps-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_checking,public" -t -c "\i gppdb/init-data/checking/1.base-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_checking,public" -t -c "\i gppdb/init-data/checking/3.cnaps-all-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_notice,public" -t -c "\i gppdb/init-data/notice/1.base-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_notice,public" -t -c "\i gppdb/init-data/notice/1.message_catalog-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_notice,public" -t -c "\i gppdb/init-data/notice/2.bussiness_event-cnaps-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_notice,public" -t -c "\i gppdb/init-data/notice/2.bussiness_event-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_position,public" -t -c "\i gppdb/init-data/position/1.base-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_position,public" -t -c "\i gppdb/init-data/position/2.cnaps-rule-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_position,public" -t -c "\i gppdb/init-data/position/3.base-forecast-init.sql" >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_routing,public" -t -c "\i gppdb/init-data/routing/1.base-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_routing,public" -t -c "\i gppdb/init-data/routing/3.cnaps-all-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_security,public" -t -c "\i gppdb/init-data/security/1.navigation-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_security,public" -t -c "\i gppdb/init-data/security/2.permission-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_security,public" -t -c "\i gppdb/init-data/security/3.admin_role-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/1.system_param-cfets-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/1.system_param-cnaps-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/1.system_param-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/2.currency-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/3.dashboard-cnaps-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/3.dashboard-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/4.template_table-cnaps-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/4.template_table-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/5.data_export-cnaps-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/5.data_export-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/6.multi-tenancy-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/7.bank_info-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/8.sequence-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/9.data_dictionary-cnaps-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_settings,public" -t -c "\i gppdb/init-data/settings/9.data_dictionary-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_workflow,public" -t -c "\i gppdb/init-data/workflow/1.business_view-cnaps-init.sql"  >>log/$LogFile 2>&1
ksql "host=${HOST} port=54321 user=gpp dbname=GPPDB options=-csearch_path=nupp_workflow,public" -t -c "\i gppdb/init-data/workflow/1.business_view-init.sql"  >>log/$LogFile 2>&1
sed -i "/WARNING/d" log/$LogFile
if [[ `grep -c -i "ERROR" log/$LogFile` -ne 0 || `grep -c "No such file or directory" log/$LogFile` -ne 0 || `grep -c "command not found" log/$LogFile` -ne 0 ]] ; then
  echo $version "upgrade_ksql_gpp update fail!"
  echo "GPP UPDATE FAIL!" >> log/$LogFile
else
  echo $version "upgrade_ksql_gpp update success!"
  echo "GPP UPDATE SUCCESS!" >> log/$LogFile
fi
